package com.theaf.basemodule.web.controller;

import com.theaf.basemodule.common.api.DicService;
import com.theaf.basemodule.common.condition.DicCondition;
import com.theaf.basemodule.common.vo.dic.DicDataVO;
import com.theaf.basemodule.common.vo.dic.DicVO;
import com.theaf.core.web.ResultHandler;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @Author:songwenke
 * @Description:字典Controller
 * @Date:create in 16:15 2017/12/25
 * @Modified By:
 **/
@RestController
@RequestMapping(value="/dic")
@Api(description="字典controller")
public class DicController {
    @Autowired
    private DicService dicService;

    @RequestMapping(value = "/list",  method = RequestMethod.POST)
    @ApiOperation(value = "字典列表查询", notes = "典列表查询", response = DicVO.class)
    public Object list(@RequestBody @ApiParam(name="查询条件",value="传入json格式",required=true) DicCondition condition){
        return ResultHandler.success(dicService.findByCondition(condition));
    }

    @RequestMapping(value = "/data/{tag}",  method = RequestMethod.GET)
    @ApiOperation(value = "查询子数据", notes = "典列表查询", response = DicDataVO.class)
    @ApiImplicitParam(value = "字典标识" , name = "tag" , dataType = "string" , paramType = "path",required=true)
    public Object data(@PathVariable String tag){
        return ResultHandler.success(dicService.findDataByTag(tag));
    }

    @RequestMapping(value = "/get/{tag}",  method = RequestMethod.GET)
    @ApiOperation(value = "查询字典", notes = "字典对象", response = DicVO.class)
    @ApiImplicitParam(value = "字典标识" , name = "tag" , dataType = "string" , paramType = "path",required=true)
    public Object get(@PathVariable String tag){
        return ResultHandler.success(dicService.findByTag(tag));
    }

    @RequestMapping(value = "/save",  method = RequestMethod.POST)
    @ApiOperation(value = "保存字典数据", notes = "保存字典数据", response = DicVO.class)
    public Object save(@RequestBody @ApiParam(name="保存字典数据",value="传入json格式",required=true) DicVO dicVo){
        dicService.save(dicVo);
        return ResultHandler.success(true);
    }
    @RequestMapping(value = "/delete/{tag}",  method = RequestMethod.PUT)
    @ApiOperation(value = "删除字典", notes = "保存参数", response = Boolean.class)
    @ApiImplicitParam(value = "字典标识" , name = "tag" , dataType = "string" , paramType = "path",required=true)
    public Object delete(@PathVariable("tag") String tag){
        dicService.delete(tag);
        return ResultHandler.success(true);
    }
}